﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Streams_Exceptions
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                System.IO.TextReader tr = new System.IO.StreamReader(this.textBox1.Text);

                try
                {
                    this.richTextBox1.Text = tr.ReadToEnd();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    tr.Close();
                }

            }
            catch (System.IO.FileNotFoundException ex)
            {
                MessageBox.Show("Sorry, the file does not exist.");
            }
            catch (System.UnauthorizedAccessException ex)
            {
                MessageBox.Show("Sorry, you lack sufficient privileges.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
